//
//  MBFooterBannerCell.m
//  Meboo
//
//  Created by kyo on 2024/3/11.
//

#import "MBFooterBannerCell.h"
#import "Meboo-Swift.h"
@interface MBFooterBannerCell ()


@property (nonatomic, strong) MBLottieView *lottieView;
@end

@implementation MBFooterBannerCell
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        [self createSubView];
    }
    return self;
}

- (void)setImageUrl:(NSString *)imageUrl {
    _imageUrl = imageUrl;
    self.lottieView.hidden = NO;
    __WeakSelf
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:nil completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        weakSelf.lottieView.hidden = YES;
    }];
}

- (void) createSubView {
    self.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:255 / 255.0 blue:255 / 255.0 alpha:0];
    self.layer.cornerRadius = MBHeightScale(10);
    
    [self.contentView addSubview:self.imageView];
    [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    
    [self.contentView addSubview:self.lottieView];
    [self.lottieView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    
    [self.lottieView layoutIfNeeded];
    [self.lottieView showWithName:@"imageLoading.json" loop:YES finishState:YES completionBlock:^(BOOL animationFinished) {
        
    }];
}

#pragma mark -  懒加载
- (UIImageView *)imageView {
   if (!_imageView) {
       _imageView = [[UIImageView alloc] init];
       _imageView.layer.cornerRadius = MBHeightScale(10);
       _imageView.layer.masksToBounds = YES;
       _imageView.contentMode = UIViewContentModeScaleAspectFill;
//       _imageView.clipsToBounds = YES;
//       _imageView.image = ImageWithName(@"login_icon_self");
       [self.contentView addSubview:_imageView];
   }
   return _imageView;
}

- (MBLottieView *)lottieView {
    if (!_lottieView) {
        _lottieView = [MBLottieView new];
    }
    return _lottieView;
}
@end
